<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>课程表</title>
</head>
<!-- 引入 layui.css -->
<link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
<!-- 引入 layui.js -->
<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="js/fun.js"></script>
<style>

</style>
<script id="timetable" type="text/html">
    <table align="center" border="1" width="800" cellspacing="0" class="layui-table layui-table-cell" style="text-align: center">
        <tr>
            <caption>课程表</caption>
        </tr>

        <tr>
            <th>序号</th>
            <th>星期一</th>
            <th>星期二</th>
            <th>星期三</th>
            <th>星期四</th>
            <th>星期五</th>
            <th>星期六</th>
            <th>星期日</th>
        </tr>

        {{#  layui.each(d.range, function(index2,item2){ }}

        <tr>

            <td>{{item2}} ({{timeMap.get(item2)}})</td>
<!--            循环外面的星期-->
            {{#  layui.each(d.list, function(index,item){ }}





            {{#  if(eval(item.data).get(item2)){ }}
           <td>{{eval(item.data).get(item2).name}}@{{eval(item.data).get(item2).teachername}}  {{eval(item.data).get(item2).roomname}}[{{eval(item.data).get(item2).roomaddress}}]</td>
            {{#  } else { }}
            <td> </td>
            {{#  } }}





            {{#  }); }}
        </tr>
        {{#  }); }}
    </table>
</script>
<body align="center">
<div style="text-align: center" id="table">

</div>
</body>
<script>


        window.timeMap = new Map();
        timeMap.set(1,"10:00");
        timeMap.set(2,"10:50");
        timeMap.set(3,"11:50");
        timeMap.set(4,"12:40");
        timeMap.set(5,"13:30");
        timeMap.set(6,"14:15");
        timeMap.set(7,"15:30");
        timeMap.set(8,"16:20");
        timeMap.set(9,"17:20");
        timeMap.set(10,"18:10");
        timeMap.set(11,"19:00");
        timeMap.set(12,"20:30");

    // getData("1,1,3;2,2,3")

    layui.use(['laytpl','form'], function(){
        window.laytpl = layui.laytpl
        window.form = layui.form

        $.post(Api+"/course/timetable",{
            stuid:getCookie("userid")
        },function (res){
            if(res.code == "200"){

                window.DayMap1 = new Map();
                window.DayMap2 = new Map();
                window.DayMap3 = new Map();
                window.DayMap4 = new Map();
                window.DayMap5 = new Map();
                window.DayMap6 = new Map();
                window.DayMap7 = new Map();


                res.data.forEach((data)=>{
                    //解析到的temp1为每一天段的数据
                    var temp1 = data.timecontent.split(";")


                    temp1.forEach((temp)=>{
                        //temp2为每一段数据的解析，分别是第几周，开始课程，结束课程
                        var temp2 = temp.split(",")


                    //    下面可以开始填充map
                        if(temp2[0] == "1"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap1.set(i,data)
                            }
                        }else if(temp2[0] == "2"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap2.set(i,data)
                            }
                        }else if(temp2[0] == "3"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap3.set(i,data)
                            }
                        }else if(temp2[0] == "4"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap4.set(i,data)
                            }
                        }else if(temp2[0] == "5"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap5.set(i,data)
                            }
                        }else if(temp2[0] == "6"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap6.set(i,data)
                            }
                        }else if(temp2[0] == "7"){
                            for (let i = parseInt (temp2[1]);i<=parseInt (temp2[2]);i++){
                                DayMap7.set(i,data)
                            }
                        }


                    })


                })
                console.log(DayMap1)


                var getTpl = timetable.innerHTML
                    ,view = document.getElementById('table');
                var model = {
                    "range":[1,2,3,4,5,6,7,8,9,10,11,12],
                    "list": [{
                        index:1,
                        data:"DayMap1"
                        },
                        {
                            index:2,
                            data:"DayMap2"
                        },
                        {
                            index:3,
                            data:"DayMap3"
                        },
                        {
                            index:4,
                            data:"DayMap4"
                        },
                        {
                            index:5,
                            data:"DayMap5"
                        },
                        {
                            index:6,
                            data:"DayMap6"
                        },
                        {
                            index:7,
                            data:"DayMap7"
                        }]
                }
                laytpl(getTpl).render(model, function(html){
                    view.innerHTML = html;
                    form.render()
                });
            }else{
                layer.msg("数据获取失败")
            }
        })

    });

        //导出excel
        function toExcel(){
            //window.location.href='<%=basePath%>pmb/excelShowInfo.do';
            //获取表格
            var exportFileContent = document.getElementById(".layui-table").outerHTML;
            //设置格式为Excel，表格内容通过btoa转化为base64，此方法只在文件较小时使用(小于1M)
            //exportFileContent=window.btoa(unescape(encodeURIComponent(exportFileContent)));
            //var link = "data:"+MIMEType+";base64," + exportFileContent;
            //使用Blob
            var blob = new Blob([exportFileContent], {type: "text/plain;charset=utf-8"});     	//解决中文乱码问题
            blob =  new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
            //设置链接
            var link = window.URL.createObjectURL(blob);
            var a = document.createElement("a");    //创建a标签
            a.download = "课程表.xls";  //设置被下载的超链接目标（文件名）
            a.href = link;                            //设置a标签的链接
            document.body.appendChild(a);            //a标签添加到页面
            a.click();                                //设置a标签触发单击事件
            document.body.removeChild(a);            //移除a标签
        }
</script>
</html>